package com.ac.util;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;

import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Component;

import com.ac.model.FileLog;

import cn.hutool.core.io.FileUtil;
import lombok.AllArgsConstructor;

@Component
@AllArgsConstructor
public class DBInit {

	static DBInit manger;

	final MongoTemplate mongo;

	@PostConstruct
	public void init() {
		manger = this;
	}

	/**
	 * 备份过去的数据添加到数据库
	 */
	public static void run() {

		String readString = FileUtil.readString("D:\\repo\\code\\veigar\\ssly\\备份\\life_article.js", "UTF-8");
//		System.out.println(readString);
		String[] sps = readString.split("/static_file/upload/");
		List<FileLog> fileloglist = new ArrayList<FileLog>();
		for (int i = 0; i < sps.length; i++) {
//			System.out.println(sps[i]);
			if (sps[i].indexOf("62f7d174e2a4411aec0ca187x") != -1
					|| sps[i].indexOf("61f7d174e2a4411aec0ca187x") != -1) {
				String[] sp1 = sps[i].split("\\.");
				String[] sp2 = sp1[0].split("/");
				String userId = sp2[0];
				String filename = sp2[1];
				String type = sp1[1].substring(0, 3);
//				System.out.println(userId + "-" + filename + "-" + type);
				FileLog fileLogInfo = new FileLog();
				fileLogInfo.insert();
				fileLogInfo.setName(filename);
				fileLogInfo.setUserId(userId);
				fileLogInfo.setType(type);
				fileLogInfo.setOpen(true);
				fileloglist.add(fileLogInfo);
			}
		}
//		System.out.println(fileloglist.size());
//		DBInit.manger.mongo.insertAll(fileloglist);
	}

}
